package com.trade.system.filter;

import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;

/**
 * Class Description: 过滤器配置类
 *
 * @Version v1.0 2017/9/16 23:17
 * @JDK version 1.8.0_51
 * @Author zfb
 */
@Configuration
public class FilterConfiguration {

    /**
     * FilterRegistrationBean
     * 用来配置urlpattern 来确定哪些路径触发filter
     */
    @Bean
    public FilterRegistrationBean someFilterRegistration() {

        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(CORSFilter());
        registration.addUrlPatterns("/*");
        registration.setOrder(1); //设置执行顺序
        return registration;
    }

    /**
     * 使用annotation tag来取代<bean></bean>
     */
    @Bean
    public Filter CORSFilter() {
        return new CORSFilter();
    }
}
